package com.bishe.demo.modules.other.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.common.entity.SearchBean;
import com.bishe.demo.modules.other.entity.Image;
import com.bishe.demo.modules.other.service.ImageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ImageController {
    @Autowired
    private ImageService imageService;

    @PostMapping(value = "/image", consumes = "application/json")
    ResultEntity<Image> insertImage(@RequestBody Image image) {
        return imageService.insertImage(image);
    }

    @DeleteMapping("/image/{imageId}")
    ResultEntity<Image> deleteImageByImageId(@PathVariable int imageId) {
        return imageService.deleteImageByImageId(imageId);
    }

    @GetMapping("/image/{imageId}")
    Image getImageByImageId(@PathVariable int imageId) {
        return imageService.getImageByImageId(imageId);
    }

    @GetMapping("/images/{sceneryId}")
    List<Image> getImagesBySceneryId(@PathVariable int sceneryId) {
        return imageService.getImagesBySceneryId(sceneryId);
    }

    @GetMapping("/images/v2/{travelId}")
    List<Image> getImageByTravelId(@PathVariable int travelId) {
        return imageService.getImageByTravelId(travelId);
    }

    @PostMapping(value = "/images", consumes = "application/json")
    PageInfo<Image> getImagesBySearchBean(@RequestBody SearchBean searchBean) {
        return imageService.getImagesBySearchBean(searchBean);
    }

}
